package Demo08.Demo0828;

public class Class {
    public static void main1(String[] args) {
       /* int[] a = new int[3];
        fac(a);
        for(int x:a){
            System.out.println(x);
        }*/
        int[] arr = new int[]{1,2,3,4,5,6,7};
        myToString(arr);
    }
    public static void myToString(int[] a){
        String myString = "[";
        for (int i = 0; i < a.length- 1; i++) {
            myString += a[i] + ",";
        }
        myString += a[a.length - 1] + "]";
        System.out.println(myString);
    }
    public static void fac(int[] a){
        a = new int[5];
        a[0] = 100;
        a[1] = 200;
    }

    public static void main(String[] args) {
        int[] a = new int[]{1,2,3,4,5,6,7};
        System.out.println(binarySearch(a,6));
    }//这一部分用来测试二分查找

    public static int binarySearch(int[] a,int key){
        int left = 0;
        int right = a.length - 1;
        while(left <= right){
            int mid = left + ((right - left) >> 1);
            if(key == a[mid]){
                return mid;
            }else if(key > a[mid]){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        return -1;
    }
}
